extends Node2D

signal on_save_game_data()

func _ready() -> void:
	#if not multiplayer.is_server() : return
	call_deferred("_init_save_game_data_signal")
	call_deferred("_init_save_game_data_timer")

func _auto_save_game_data() -> void :
	_save_game_data()

func _save_game_data() -> void :
	var game_data = Global.current_game_data
	var game_id = game_data.game_id
	SceneManage.call_deferred("_save_game_data_rw",game_id,"player_data",Global.current_player_data._get_stuct(),2)

func _init_save_game_data_signal() -> void :
	on_save_game_data.connect(_save_game_data)

func _init_save_game_data_timer() -> void :
	var auto_save_timer = Timer.new()
	auto_save_timer.autostart = true
	auto_save_timer.wait_time = 1.0 * 5
	auto_save_timer.timeout.connect(_auto_save_game_data)
	add_child(auto_save_timer)
